home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt85may.lbr
/
NIM.BQS
/
NIM.BAS
Wrap
BASIC Source File
|
1985-09-15
|
3KB
|
89 lines
10 '***********************************************
20 '* NIM *
30 '* BY BOB KUROSAKA *
40 '***********************************************
50 CLS
60 DEFINT A-Z:VICTORY$="NO"
70 REM DEFINE INITIAL BOARD CONDITIONS
80 INPUT "ENTER THE NUMBER OF ROWS (3<=ROWS<=18)";ROWS
90 IF ROWS<3 OR ROWS>18 THEN PRINT "MUST BE BETWEEN 3 AND 18":GOTO 80
100 DIM ROW(ROWS)
110 FOR I=1 TO ROWS
120 PRINT "ENTER NUMBER OF OBJECTS (1 TO 59) IN ROW ";I
130 INPUT ROW(I)
140 IF ROW(I)<1 OR ROW(I)>59 THEN PRINT "NUMBER MUST BE BETWEEN 1 AND 59": GOTO 120
150 NEXT I
160 GOSUB 540:REM DRAW THE BOARD
170 INPUT "ENTER 1 TO MOVE FIRST, 2 TO MOVE SECOND";MOVE
180 IF MOVE<1 OR MOVE>2 THEN 170
190 ON MOVE GOTO 210,340
200 REM
210 REM PLAYER'S MOVE SEQUENCE
220 REM
230 PLAYER$="YOU"
240 INPUT "ROW";ROW
250 IF ROW<1 OR ROW>ROWS THEN PRINT "INVALID ROW":GOTO 240
260 INPUT "REMOVE";REMOVE
270 IF REMOVE>ROW(ROW) OR REMOVE<1 THEN PRINT "INVALID":GOTO 240
280 ROW(ROW)=ROW(ROW)-REMOVE
290 GOSUB 540:REM REDRAW BOARD
300 IF VICTORY$="YES" THEN 500
310 REM PAUSE LONG ENOUGH TO SEE THE BOARD
320 FOR I=1 TO 5000:NEXT
330 REM
340 REM COMPUTER'S MOVE SEQUENCE
350 REM
360 PLAYER$="I"
370 REM DETERMINE PARITY OF THE BOARD
380 PARITY=ROW(1)
390 FOR I=2 TO ROWS
400 PARITY=(PARITY OR ROW(I)) AND (NOT(PARITY AND ROW(I)))
410 NEXT I
420 REM CHOOSE MOVE-SELECTION ROUTINE DEPENDING ON BOARD SAFETY
430 IF PARITY=0 THEN GOSUB 690 ELSE GOSUB 790
440 REM DRAW THE NEW BOARD
450 GOSUB 540
460 REM ANNOUNCE COMPUTER MOVE
470 PRINT "I HAVE REMOVED ";REMOVE;" PIECES FROM ROW ";ROW
480 REM LOOP FOR NEXT MOVE SEQUENCE
490 IF VICTORY$="NO" THEN 210
500 END
510 REM END OF MAIN PROCEDURE
520 REM BEGINNING OF SUBROUTINES
530 REM
540 REM BOARD-DRAWING ROUTINE
550 REM
560 CLS
570 STATUS=0 'HOW MANY ROWS ARE EMPTY?
580 FOR I=1 TO ROWS
590 PRINT "ROW ";I;"(";ROW(I);")";TAB(20);
600 IF ROW(I)=0 THEN STATUS=STATUS+1:GOTO 640
610 FOR J=1 TO ROW(I)
620 PRINT "/";
630 NEXT J
640 PRINT
650 NEXT I
660 IF STATUS=ROWS THEN PRINT PLAYER$;" WON":VICTORY$="YES"
670 RETURN
680 REM
690 REM NO GOOD MOVES ROUTINE
700 REM
710 REMOVE=0:ROW=0
720 WHILE REMOVE=0
730 ROW=ROW+1
740 IF ROW(ROW)>0 THEN REMOVE=1
750 WEND
760 ROW(ROW)=ROW(ROW)-REMOVE
770 RETURN
780 REM
790 REM FIND THE GOOD MOVE ROUTINE
800 REM
810 REMOVE=0:ROW=0
820 WHILE REMOVE=0
830 ROW=ROW+1
840 RETAIN=(ROW(ROW) OR PARITY) AND (NOT(ROW(ROW) AND PARITY))
850 IF RETAIN<ROW(ROW) THEN REMOVE=ROW(ROW)-RETAIN
860 WEND
870 ROW(ROW)=ROW(ROW)-REMOVE
880 RETURN